/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "oled_task.h"
#include "nrf_task.h"
#include "motor_task.h"
#include "led_task.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
osThreadId led_TaskHandle;
osThreadId oled_taskHandle;
osThreadId nrf_taskHandle;
osThreadId motor_taskHandle;

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void Led_task(void const * argument);
void Oled_task(void const * argument);
void Nrf_task(void const * argument);
void Motor_task(void const * argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );

/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
static StaticTask_t xIdleTaskTCBBuffer;
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];

void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
  *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
  *ppxIdleTaskStackBuffer = &xIdleStack[0];
  *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
  /* place for user code */
}
/* USER CODE END GET_IDLE_TASK_MEMORY */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* definition and creation of led_Task */
  osThreadDef(led_Task, Led_task, osPriorityLow, 0, 128);
  led_TaskHandle = osThreadCreate(osThread(led_Task), NULL);

  /* definition and creation of oled_task */
  osThreadDef(oled_task, Oled_task, osPriorityBelowNormal, 0, 128);
  oled_taskHandle = osThreadCreate(osThread(oled_task), NULL);

  /* definition and creation of nrf_task */
  osThreadDef(nrf_task, Nrf_task, osPriorityHigh, 0, 128);
  nrf_taskHandle = osThreadCreate(osThread(nrf_task), NULL);

  /* definition and creation of motor_task */
  osThreadDef(motor_task, Motor_task, osPriorityRealtime, 0, 128);
  motor_taskHandle = osThreadCreate(osThread(motor_task), NULL);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

}

/* USER CODE BEGIN Header_Led_task */
/**
  * @brief  Function implementing the led_Task thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_Led_task */
__weak void Led_task(void const * argument)
{
  /* USER CODE BEGIN Led_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END Led_task */
}

/* USER CODE BEGIN Header_Oled_task */
/**
* @brief Function implementing the oled_task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_Oled_task */
__weak void Oled_task(void const * argument)
{
  /* USER CODE BEGIN Oled_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END Oled_task */
}

/* USER CODE BEGIN Header_Nrf_task */
/**
* @brief Function implementing the nrf_task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_Nrf_task */
__weak void Nrf_task(void const * argument)
{
  /* USER CODE BEGIN Nrf_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END Nrf_task */
}

/* USER CODE BEGIN Header_Motor_task */
/**
* @brief Function implementing the motor_task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_Motor_task */
__weak void Motor_task(void const * argument)
{
  /* USER CODE BEGIN Motor_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END Motor_task */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

